package com.smart.controller;


import cn.hutool.core.util.StrUtil;
import com.smart.entity.Result;
import com.smart.service.IDeviceTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 设备类型表 前端控制器
 * </p>
 *
 * @author Cookies
 * @since 2024-05-31
 */
@RestController
@CrossOrigin
@RequestMapping("/device-type")
@Api(tags = "设备类型相关接口")
public class DeviceTypeController {
    @Autowired
    private IDeviceTypeService deviceTypeService;

    @GetMapping
    @ApiOperation(value = "获取设备类型列表", response = Result.class)
    public Result getDeviceAllTypeList() {
        return Result.success(deviceTypeService.getDeviceAllTypeList());
    }

    @GetMapping("/{type}")
    @ApiOperation(value = "获取设备类型子类型列表", response = Result.class)
    public Result getDeviceSubTypeList(
            @PathVariable @ApiParam(name = "设备类型", required = true) String type) {
        if (StrUtil.isBlank(type)) {
            return Result.error("设备类型不能为空");
        }
        return Result.success(deviceTypeService.getDeviceSubTypeListByType(type));
    }
}
